package com.softa.common.sysconfig.flyway;

import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;

/**
 * description goes here.
 *
 * @author 杨磊
 * @date 2019/5/9 22:36
 * @since 1.0
 **/
public abstract class AbstractBaseJavaMigration extends BaseJavaMigration {

    /**
     * run
     * @param jdbc
     */
    public abstract void jdbcMigrate(JdbcTemplate jdbc);

    @Override
    public void migrate(Context context) throws Exception {
        JdbcTemplate jdbc = getJdbc(context);
        jdbcMigrate(jdbc);
    }

    private JdbcTemplate getJdbc(Context context){
        JdbcTemplate jdbc = new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true));
        return jdbc;
    }

}
